import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutterapp/Base/methodChannel/MethodChannelManager.dart';
import 'package:permission_handler/permission_handler.dart';
import 'Application.dart';
import 'Base/InitConfig.dart';

Future<Null> main() async {
  FlutterError.onError = (FlutterErrorDetails details) async {
    FlutterError.dumpErrorToConsole(details);
    Zone.current.handleUncaughtError(details.exception, details.stack);
  };

  runZoned<Future<void>>(() async {
    WidgetsFlutterBinding.ensureInitialized();
    await InitConfig.initApp();
    reqPermissions();
    runApp(new Application());
  }, onError: (error, stackTrace) async {
    await reportError(error, stackTrace);
  });
}

void reqPermissions() async {
  await Permission.storage.request();
  await Permission.location.request();
}

reportError(error, stackTrace) {
  String type = "flutter ERR";
  MethodChannelManager.getInstance().invoke(MethodTypes.ERR_REPORT, {
    "type": type,
    "error": error.toString(),
    "stackTrace": stackTrace.toString(),
    "extraInfo": {"k": "v"},
  });
}
